﻿#region NameSapceces

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using WebReference;
using System.Text;
using PrimaryKeyFunction;
using System.IO;
#endregion


public partial class Search_FilterData : System.Web.UI.Page
{
    Service objServices = new Service();

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack == true)
        {

            List<string> FinalcheckItem = (List<string>)Session["SearchCheckedItem"];

            for (int k = 0; FinalcheckItem.Count > k; k++)
            {
                #region Material Textboxes
                //Material Textboxes
                if (FinalcheckItem[k].ToString() == "ChkMaterialName")
                {
                    trMaterial.Visible = true;
                    trMaterialName.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "ChkMaterialSource")
                {
                    trMaterial.Visible = true;
                    trMaterialSource.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "ChkMaterialHandlingHistory")
                {
                    trMaterial.Visible = true;
                    trMaterialHandlingHistory.Visible = true;
                }
                #endregion

                #region Yield Textboxes
                //Material Textboxes
                if (FinalcheckItem[k].ToString() == "chkYieldGas")
                {
                    trYield.Visible = true;
                    trYieldGas.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkYieldTar")
                {
                    trYield.Visible = true;
                    trYieldTar.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkYieldChr")
                {
                    trYield.Visible = true;
                    trYieldChr.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkYieldLiquid")
                {
                    trYield.Visible = true;
                    trYieldLiquid.Visible = true;
                }
                #endregion

                #region Gas Textboxes
                //Material Textboxes
                if (FinalcheckItem[k].ToString() == "chkGasH2")
                {
                    trGas.Visible = true;
                    trGasH2.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkGasCO")
                {
                    trGas.Visible = true;
                    trGasCO.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkGasCO2")
                {
                    trGas.Visible = true;
                    trGasCO2.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkGasCH4")
                {
                    trGas.Visible = true;
                    trGasCH4.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkGasC2H4")
                {
                    trGas.Visible = true;
                    trGasC2H4.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkGasC2H2")
                {
                    trGas.Visible = true;
                    trGasC2H2.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkGasC2H6")
                {
                    trGas.Visible = true;
                    trGasC2H6.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkGasN2")
                {
                    trGas.Visible = true;
                    trGasN2.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkGasGCV")
                {
                    trGas.Visible = true;
                    trGasGCV.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkGasTar")
                {
                    trGas.Visible = true;
                    trGasTar.Visible = true;
                }
                #endregion

                #region "Analysis Related"

                #region Proximate Analysis
                if (FinalcheckItem[k].ToString() == "chkProximateAnalysisAsh")
                {
                    trProximateAnalysis.Visible = true;
                    trProximateAnalysisAsh.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkProximateAnalysisMoistureStatus")
                {
                    trProximateAnalysis.Visible = true;
                    trProximateAnalysisMoistureStatus.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkProximateAnalysisMoisture")
                {
                    trProximateAnalysis.Visible = true;
                    trProximateAnalysisMoisture.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkProximateAnalysisVolatiles")
                {
                    trProximateAnalysis.Visible = true;
                    trProximateAnalysisVolatiles.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkProximateAnalysisFixedCarbon")
                {
                    trProximateAnalysis.Visible = true;
                    trProximateAnalysisFixedCarbon.Visible = true;
                }

                #endregion

                #region Ultimate Analysis
                if (FinalcheckItem[k].ToString() == "chkUltimateAnalysisMoistureStatus")
                {
                    trUltimateAnalysis.Visible = true;
                    UltimateAnalysisMoistureStatus.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkUltimateAnalysisMoisture")
                {
                    trUltimateAnalysis.Visible = true;
                    UltimateAnalysisMoisture.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkUltimateAnalysisAsh")
                {
                    trUltimateAnalysis.Visible = true;
                    UltimateAnalysisAsh.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkUltimateAnalysisC")
                {
                    trUltimateAnalysis.Visible = true;
                    UltimateAnalysisC.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkUltimateAnalysisH")
                {
                    trUltimateAnalysis.Visible = true;
                    UltimateAnalysisH.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkUltimateAnalysisO")
                {
                    trUltimateAnalysis.Visible = true;
                    UltimateAnalysisO.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkUltimateAnalysisCl")
                {
                    trUltimateAnalysis.Visible = true;
                    UltimateAnalysisCl.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkUltimateAnalysisS")
                {
                    trUltimateAnalysis.Visible = true;
                    UltimateAnalysisS.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkUltimateAnalysisN")
                {
                    trUltimateAnalysis.Visible = true;
                    UltimateAnalysisN.Visible = true;
                }

                #endregion

                #region Structural Analysis
                if (FinalcheckItem[k].ToString() == "chkStructuralAnalysisLignin")
                {
                    trStructuralAnalysis.Visible = true;
                    trStructuralAnalysisLignin.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkStructuralAnalysisLigninMethod")
                {
                    trStructuralAnalysis.Visible = true;
                    trStructuralAnalysisLigninmethod.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkStructuralAnalysisCellulose")
                {
                    trStructuralAnalysis.Visible = true;
                    trStructuralAnalysisCellulose.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkStructuralAnalysisHemiCellulose")
                {
                    trStructuralAnalysis.Visible = true;
                    trStructuralAnalysisHemiCellulose.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkStructuralAnalysisExtractives")
                {
                    trStructuralAnalysis.Visible = true;
                    trStructuralAnalysisExtractives.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkStructuralAnalysisCellWall")
                {
                    trStructuralAnalysis.Visible = true;
                    trStructuralAnalysisCellWall.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkStructuralAnalysisPectin")
                {
                    trStructuralAnalysis.Visible = true;
                    trStructuralAnalysisPectin.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkStructuralAnalysisSol_Sugar_Sta")
                {
                    trStructuralAnalysis.Visible = true;
                    trStructuralAnalysisSol_Sugar_Sta.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkStructuralAnalysisXylan")
                {
                    trStructuralAnalysis.Visible = true;
                    trStructuralAnalysisXylan.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkStructuralAnalysisGlucomannan")
                {
                    trStructuralAnalysis.Visible = true;
                    trStructuralAnalysisGlucomannan.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkStructuralAnalysisGlucomannan")
                {
                    trStructuralAnalysis.Visible = true;
                    trStructuralAnalysisGlucomannan.Visible = true;
                }

                if (FinalcheckItem[k].ToString() == "chkStructuralAnalysisGalactin")
                {
                    trStructuralAnalysis.Visible = true;
                    trStructuralAnalysisGalactin.Visible = true;
                }

                if (FinalcheckItem[k].ToString() == "chkStructuralAnalysisArabinan")
                {
                    trStructuralAnalysis.Visible = true;
                    trStructuralAnalysisArabinan.Visible = true;
                }

                if (FinalcheckItem[k].ToString() == "chkStructuralAnalysisMannan")
                {
                    trStructuralAnalysis.Visible = true;
                    trStructuralAnalysisMannan.Visible = true;
                }

                #endregion

                #region AshAnalysis Textboxes
                //Ashanalysis Textboxes
                if (FinalcheckItem[k].ToString() == "chkAshanalysisCO2")
                {
                    trAshAnalysis.Visible = true;
                    AshAnalysisCO2.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkAshanalysisSO3")
                {
                    trAshAnalysis.Visible = true;
                    AshAnalysisSO3.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkAshanalysisSiO2")
                {
                    trAshAnalysis.Visible = true;
                    AshAnalysisSiO2.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkAshanalysisCaO")
                {
                    trAshAnalysis.Visible = true;
                    AshAnalysisCaO.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkAshanalysisMgO")
                {
                    trAshAnalysis.Visible = true;
                    AshAnalysisMgO.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkAshanalysisK2O")
                {
                    trAshAnalysis.Visible = true;
                    AshAnalysisK2O.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkAshanalysisTiO2")
                {
                    trAshAnalysis.Visible = true;
                    AshAnalysisTiO2.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkAshanalysisPb")
                {
                    trAshAnalysis.Visible = true;
                    AshAnalysisPb.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkAshanalysisCd")
                {
                    trAshAnalysis.Visible = true;
                    AshAnalysisCd.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkAshanalysisCl")
                {
                    trAshAnalysis.Visible = true;
                    AshAnalysisCl.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkAshanalysisCu")
                {
                    trAshAnalysis.Visible = true;
                    AshAnalysisCu.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkAshanalysisHg")
                {
                    trAshAnalysis.Visible = true;
                    AshAnalysisHg.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkAshanalysisCr")
                {
                    trAshAnalysis.Visible = true;
                    AshAnalysisCr.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkAshanalysisNa2O")
                {
                    trAshAnalysis.Visible = true;
                    AshAnalysisNa2O.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkAshanalysisP2O5")
                {
                    trAshAnalysis.Visible = true;
                    AshAnalysisP2O5.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkAshanalysisAl2O3")
                {
                    trAshAnalysis.Visible = true;
                    AshAnalysisAl2O3.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkAshanalysisFe2O3")
                {
                    trAshAnalysis.Visible = true;
                    AshAnalysisFe2O3.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkAshanalysisMn")
                {
                    trAshAnalysis.Visible = true;
                    AshAnalysisMn.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkAshanalysisProductionMethod")
                {
                    trAshAnalysis.Visible = true;
                    AshAnalysisProductionMethod.Visible = true;
                }
                #endregion

                #region Calorific analysis Textboxes
                //Calorific Analysis Textboxes
                if (FinalcheckItem[k].ToString() == "chkCalorificAnalysisMoistureStatus")
                {
                    trCalorificAnalysis.Visible = true;
                    trCalorificAnalysisMoistureStatus.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkCalorificAnalysisHHV")
                {
                    trCalorificAnalysis.Visible = true;
                    trCalorificAnalysisHHV.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkCalorificAnalysisLHV")
                {
                    trCalorificAnalysis.Visible = true;
                    trCalorificAnalysisLHV.Visible = true;
                }
                #endregion

                #endregion

                #region Conversion conditions Textboxes
                //Conversion Conditions Textboxes
                if (FinalcheckItem[k].ToString() == "chkConversionConConvRegime")
                {
                    trConversioncond.Visible = true;
                    trConversionCondConvRegime.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkConversionConReactorConf")
                {
                    trConversioncond.Visible = true;
                    trConversionCondReactorConf.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkConversionConBedmedium")
                {
                    trConversioncond.Visible = true;
                    trConversionCondBedmedium.Visible = true;
                }

                if (FinalcheckItem[k].ToString() == "chkConversionConFeedsystem")
                {
                    trConversioncond.Visible = true;
                    trConversionCondFeedsystem.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkConversionConGasifimethod")
                {
                    trConversioncond.Visible = true;
                    trConversionCondGasifimethod.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkConversionConasBiomassRatio")
                {
                    trConversioncond.Visible = true;
                    trConversionCondGasBiomassRatio.Visible = true;
                }


                if (FinalcheckItem[k].ToString() == "chkConversionConFeedRateMin")
                {
                    trConversioncond.Visible = true;
                    trConversionCondFeedRateMin.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkConversionConFeedRateMax")
                {
                    trConversioncond.Visible = true;
                    trConversionCondFeedRateMax.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkConversionConTem")
                {
                    trConversioncond.Visible = true;
                    trConversionCondTemp.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkConversionConPressure")
                {
                    trConversioncond.Visible = true;
                    trConversionCondPressure.Visible = true;
                }



                if (FinalcheckItem[k].ToString() == "chkConversionConFeedRateMin")
                {
                    trConversioncond.Visible = true;
                    trConversionCondFeedRateMin.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkConversionConFeedRateMax")
                {
                    trConversioncond.Visible = true;
                    trConversionCondFeedRateMax.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkConversionConHeatRateMin")
                {
                    trConversioncond.Visible = true;
                    trConversionCondHeatrateMin.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkConversionConHeatRateMax")
                {
                    trConversioncond.Visible = true;
                    trConversionCondHeatrateMax.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkConversionConResTimeMin")
                {
                    trConversioncond.Visible = true;
                    trConversionCondResTimeMin.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkConversionConResTimeMax")
                {
                    trConversioncond.Visible = true;
                    trConversionCondResTimeMax.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkConversionConSweepGasVol")
                {
                    trConversioncond.Visible = true;
                    trConversionCondSweepGasVol.Visible = true;
                }
                #endregion

                #region Char Textboxes
                //Material Textboxes
                if (FinalcheckItem[k].ToString() == "chkChrH")
                {
                    trChar.Visible = true;
                    trCharH.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkChrC")
                {
                    trChar.Visible = true;
                    trCharC.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkChrN")
                {
                    trChar.Visible = true;
                    trCharN.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkChrS")
                {
                    trChar.Visible = true;
                    trCharS.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkChrAsh")
                {
                    trChar.Visible = true;
                    trCharAsh.Visible = true;
                }
              
                #endregion

                #region Liquid components Textboxes
               
                if (FinalcheckItem[k].ToString() == "chkLiquidComponentAqueous")
                {
                    trLiquidComponents.Visible = true;
                    trLiquidComponentsAqueous.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkLiquidComponentOil")
                {
                    trLiquidComponents.Visible = true;
                    trLiquidComponentsOil.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkLiquidComponentWater")
                {
                    trLiquidComponents.Visible = true;
                    trLiquidComponentsWater.Visible = true;
                }
                

                #endregion

                #region Oil components Textboxes

                if (FinalcheckItem[k].ToString() == "chkOilComponentAliphatic")
                {
                    trOilComponents .Visible = true;
                    trOilComponentsAliphatic.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkOilComponentAromatic")
                {
                    trOilComponents.Visible = true;
                    trOilComponentsAromatic.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkOilComponentPolar")
                {
                    trOilComponents.Visible = true;
                    trOilComponentsPolar.Visible = true;
                }


                #endregion

                #region "Oil Physical Properties"

                if (FinalcheckItem[k].ToString() == "chkOilPhysicalPropertiesDensity")
                {
                    trOilPhysicalProperties.Visible = true;
                    trOilPhysicalPropertiesDensity.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkOilPhysicalPropertiesViscosity")
                {
                    trOilPhysicalProperties.Visible = true;
                    trOilPhysicalPropertiesViscosity.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkOilPhysicalPropertiesViscosityTemp")
                {
                    trOilPhysicalProperties.Visible = true;
                    trOilPhysicalPropertiesViscosityTemp.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkOilPhysicalPropertiesFlashPoint")
                {
                    trOilPhysicalProperties.Visible = true;
                    trOilPhysicalPropertiesFlashPoint.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkOilPhysicalPropertiesPourPoint")
                {
                    trOilPhysicalProperties.Visible = true;
                    trOilPhysicalPropertiesPoutPoint.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkOilPhysicalPropertiesPh")
                {
                    trOilPhysicalProperties.Visible = true;
                    trOilPhysicalPropertiesPh.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkOilPhysicalPropertiesHHV")
                {
                    trOilPhysicalProperties.Visible = true;
                    trOilPhysicalPropertiesHHV.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkOilPhysicalPropertiesHeatOfCompution")
                {
                    trOilPhysicalProperties.Visible = true;
                    trOilPhysicalPropertiesHeatOfCompution.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkOilPhysicalPropertiesWaterContent")
                {
                    trOilPhysicalProperties.Visible = true;
                    trOilPhysicalPropertiesWaterContent.Visible = true;
                }
                if (FinalcheckItem[k].ToString() == "chkOilPhysicalPropertiesContradsenCarbon")
                {
                    trOilPhysicalProperties.Visible = true;
                    trOilPhysicalPropertiesContradsenCarbon.Visible = true;
                }


                #endregion



            }
        }
    }

    protected void btnExport_Click(object sender, EventArgs e)
    {
        DataTable dt = (DataTable)Session["FilterExperiment"];
        Functions.ExportToExcel(dt, Response, "Filterd Experiment");

    }

    private void bindDataGrid()
    {
        dgFinalResult.DataSource = (DataTable)Session["FilterExperiment"];
        dgFinalResult.DataBind();
    }

    protected void dgFinalResult_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        dgFinalResult.PageIndex = e.NewPageIndex;
        bindDataGrid();
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();

        //This is the final query
        string FinalQuery;

        //This is used to populate the attributes
        StringBuilder Attributes = new StringBuilder();

        //This is used to validate column based on the tables from Table list.
        StringBuilder ValidationColumns = new StringBuilder();


        //This is used to add the columns 
        StringBuilder StringColumns = new StringBuilder();

        //This is used to store the table which are checked
        StringBuilder FinalTables = new StringBuilder();



        //Get the checked tables
        List<string> Tables = (List<string>)Session["CheckedItem"];

        //Get the checked columns
        List<string> QueryColumns = (List<string>)Session["QueryColumn"];

        #region "Tables Fore Loop"
        //Genetate the part of query based on the table names from the Table list. 
        for (int i = 0; Tables.Count > i; i++)
        {
            int totalTable = Tables.Count - 1;

            #region Material Table
            if (Tables[i].ToString() == "Material")
            {
                //If K=0 then there is only one table in the Table list.
                if (i == 0)
                {
                    Attributes.Append("material.name as MaterialName,material.source as MaterialSource,material.handlingHistory as MaterialHandlingHistory");
                    ValidationColumns.Append(" and material.id=experiment.material_fk ");
                }
                else
                {
                    Attributes.Append(",material.name as MaterialName,material.source as MaterialSource,material.handlingHistory as MaterialHandlingHistory");

                    //if k=total table which means that table is the last/final table from the Table list.
                    if (i == totalTable)
                    {
                        ValidationColumns.Append(" and material.id=experiment.material_fk;");
                    }
                    else
                    {
                        ValidationColumns.Append(" and material.id=experiment.material_fk");
                    }
                }


            }
            #endregion

            #region Conversion Condidtion Table
            if (Tables[i].ToString() == "convconditions")
            {
                if (i == 0)
                {
                    Attributes.Append("convconditions.conv_Regime as ConversionRegime,convconditions.reactorConfig as ReactorConfiguration,convconditions.bedMedium as BedMedium,convconditions.feedSystem as FeedSystem,convconditions.gasificationMed as GasificationMethod,convconditions.gasBiomassRatio as GasBioMassRatio,convconditions.feedRate_min as FeedRateMin,convconditions.feedRate_max as FeedRateMax,convconditions.temp as Temperature,convconditions.pressure as Pressure,convconditions.heatRate_min as HeatRateMinimum,convconditions.heatRate_max as HeatRateMaximum,convconditions.resTime_min as ResidenceTimeMinimum,convconditions.resTime_max as ResidenceTimeMaximum,convconditions.sweptGasVelocity as SweepGasVelocity");
                    ValidationColumns.Append(" and convconditions.id=experiment.convcond_fk ");
                }
                else
                {
                    Attributes.Append(",convconditions.conv_Regime as ConversionRegime,convconditions.reactorConfig as ReactorConfiguration,convconditions.bedMedium as BedMedium,convconditions.feedSystem as FeedSystem,convconditions.gasificationMed as GasificationMethod,convconditions.gasBiomassRatio as GasBioMassRatio,convconditions.feedRate_min as FeedRateMin,convconditions.feedRate_max as FeedRateMax,convconditions.temp as Temperature,convconditions.pressure as Pressure,convconditions.heatRate_min as HeatRateMinimum,convconditions.heatRate_max as HeatRateMaximum,convconditions.resTime_min as ResidenceTimeMinimum,convconditions.resTime_max as ResidenceTimeMaximum,convconditions.sweptGasVelocity as SweepGasVelocity");
                    if (i == totalTable)
                    {
                        ValidationColumns.Append(" and convconditions.id=experiment.convcond_fk;");
                    }
                    else
                    {
                        ValidationColumns.Append(" and convconditions.id=experiment.convcond_fk");
                    }
                }

            }
            #endregion

            #region Proximate Analysis Table
            if (Tables[i].ToString() == "proxanal")
            {
                //If K=0 then there is only one table in the Table list.
                if (i == 0)
                {
                    Attributes.Append("proxanal.moistureStatus as ProximateAnalysis_MoistureStatus,proxanal.moisture as ProximateAnalysis_Moisture,proxanal.ash as ProximateAnalysis_Ash,proxanal.volatiles as ProximateAnalysis_Volatiles,proxanal.FixedCarbon as ProximateAnalysis_FixedCarbon");
                    ValidationColumns.Append(" and proxanal.id=experiment.proxanal_fk ");
                }
                else
                {
                    Attributes.Append(",proxanal.moistureStatus as ProximateAnalysis_MoistureStatus,proxanal.moisture as ProximateAnalysis_Moisture,proxanal.ash as ProximateAnalysis_Ash,proxanal.volatiles as ProximateAnalysis_Volatiles,proxanal.FixedCarbon as ProximateAnalysis_FixedCarbon");

                    //if k=total table which means that table is the last/final table from the Table list.
                    if (i == totalTable)
                    {
                        ValidationColumns.Append(" and proxanal.id=experiment.proxanal_fk;");
                    }
                    else
                    {
                        ValidationColumns.Append(" and proxanal.id=experiment.proxanal_fk ");
                    }
                }


            }
            #endregion

            #region Ultimate Analysis Table
            if (Tables[i].ToString() == "ultanal")
            {
                //If K=0 then there is only one table in the Table list.
                if (i == 0)
                {
                    Attributes.Append("ultanal.moistureStatus as UltimateAnalysis_MoistureStatus,ultanal.moisture as UltimateAnalysis_Moisture,ultanal.ash as UltimateAnalysis_Ash,ultanal.H as UltimateAnalysis_H,ultanal.C as UltimateAnalysis_C,ultanal.N as UltimateAnalysis_N,ultanal.O as UltimateAnalysis_O,ultanal.Cl as UltimateAnalysis_Cl,ultanal.S as UltimateAnalysis_S");
                    ValidationColumns.Append(" and ultanal.id=experiment.ultanal_fk ");
                }
                else
                {
                    Attributes.Append(",ultanal.moistureStatus as UltimateAnalysis_MoistureStatus,ultanal.moisture as UltimateAnalysis_Moisture,ultanal.ash as UltimateAnalysis_Ash,ultanal.H as UltimateAnalysis_H,ultanal.C as UltimateAnalysis_C,ultanal.N as UltimateAnalysis_N,ultanal.O as UltimateAnalysis_O,ultanal.Cl as UltimateAnalysis_Cl,ultanal.S as UltimateAnalysis_S");

                    //if k=total table which means that table is the last/final table from the Table list.
                    if (i == totalTable)
                    {
                        ValidationColumns.Append(" and ultanal.id=experiment.ultanal_fk;");
                    }
                    else
                    {
                        ValidationColumns.Append(" and ultanal.id=experiment.ultanal_fk ");
                    }
                }


            }
            #endregion

            #region Ash analysis Table
            if (Tables[i].ToString() == "ashanal")
            {
                //If K=0 then there is only one table in the Table list.
                if (i == 0)
                {
                    Attributes.Append("ashanal.ashProdMethod,ashanal.CO2,ashanal.SO3,ashanal.P2O5,ashanal.SiO2,ashanal.Fe2O3,ashanal.Al2O3,ashanal.CaO,ashanal.MgO,ashanal.Na2O,ashanal.K2O,ashanal.TiO2,ashanal.Pb,ashanal.Cd,ashanal.Cl,ashanal.Cu,ashanal.Hg,ashanal.Mn,ashanal.Cr");
                    ValidationColumns.Append(" and ashanal.id=experiment.ashanal_fk ");
                }
                else
                {
                    Attributes.Append(",ashanal.ashProdMethod,ashanal.CO2,ashanal.SO3,ashanal.P2O5,ashanal.SiO2,ashanal.Fe2O3,ashanal.Al2O3,ashanal.CaO,ashanal.MgO,ashanal.Na2O,ashanal.K2O,ashanal.TiO2,ashanal.Pb,ashanal.Cd,ashanal.Cl,ashanal.Cu,ashanal.Hg,ashanal.Mn,ashanal.Cr");

                    //if k=total table which means that table is the last/final table from the Table list.
                    if (i == totalTable)
                    {
                        ValidationColumns.Append(" and ashanal.id=experiment.ashanal_fk;");
                    }
                    else
                    {
                        ValidationColumns.Append(" and ashanal.id=experiment.ashanal_fk");
                    }
                }


            }
            #endregion

            #region Calorific Analysis Table
            if (Tables[i].ToString() == "calanal")
            {
                if (i == 0)
                {
                    Attributes.Append("calanal.moistureStatus,calanal.HHV,calanal.LHV");
                    ValidationColumns.Append("and calanal.id=experiment.calanal_fk ");
                }
                else
                {
                    Attributes.Append(",calanal.moistureStatus,calanal.HHV,calanal.LHV");
                    if (i == totalTable)
                    {
                        ValidationColumns.Append(" and calanal.id=experiment.calanal_fk;");
                    }
                    else
                    {
                        ValidationColumns.Append(" and calanal.id=experiment.calanal_fk");
                    }

                }

            }
            #endregion

            #region Structural Analysis Table
            if (Tables[i].ToString() == "struct")
            {
                if (i == 0)
                {
                    Attributes.Append("struct.lignin,struct.ligninMethod,struct.cellulose,struct.hemicellulose,struct.extractives,struct.cellwall,struct.pectin,struct.sol_sugars_stch,struct.xylan,struct.glucomannan,struct.galactan,struct.arabinan,struct.mannan");
                    ValidationColumns.Append("and struct.id=experiment.struct_fk ");
                }
                else
                {
                    Attributes.Append(",struct.lignin,struct.ligninMethod,struct.cellulose,struct.hemicellulose,struct.extractives,struct.cellwall,struct.pectin,struct.sol_sugars_stch,struct.xylan,struct.glucomannan,struct.galactan,struct.arabinan,struct.mannan");
                    if (i == totalTable)
                    {
                        ValidationColumns.Append(" and struct.id=experiment.struct_fk;");
                    }
                    else
                    {
                        ValidationColumns.Append(" and struct.id=experiment.struct_fk");
                    }

                }

            }
            #endregion

            #region Yield Table
            if (Tables[i].ToString() == "Yields")
            {
                //If K=0 then there is only one table in the Table list.
                if (i == 0)
                {
                    Attributes.Append("yields.gas,yields.tar,yields.liquid,yields.chr");
                    ValidationColumns.Append(" and yields.experiment_id=experiment.experiment_id ");
                }
                else
                {
                    Attributes.Append(",yields.gas,yields.tar,yields.liquid,yields.chr");

                    //if k=total table which means that table is the last/final table from the Table list.
                    if (i == totalTable)
                    {
                        ValidationColumns.Append(" and yields.experiment_id=experiment.experiment_id;");
                    }
                    else
                    {
                        ValidationColumns.Append(" and yields.experiment_id=experiment.experiment_id");
                    }
                }


            }
            #endregion

            #region Gas Table
            if (Tables[i].ToString() == "gascomp")
            {
                //If K=0 then there is only one table in the Table list.
                if (i == 0)
                {
                    Attributes.Append("gascomp.H2,gascomp.CO,gascomp.CO2,gascomp.CH4,gascomp.C2H2,gascomp.C2H4,gascomp.C2H6,gascomp.N2,gascomp.GCV,gascomp.Tar");
                    ValidationColumns.Append(" and gascomp.experiment_id=experiment.experiment_id ");
                }
                else
                {
                    Attributes.Append(",gascomp.H2,gascomp.CO,gascomp.CO2,gascomp.CH4,gascomp.C2H2,gascomp.C2H4,gascomp.C2H6,gascomp.N2,gascomp.GCV,gascomp.Tar");

                    //if k=total table which means that table is the last/final table from the Table list.
                    if (i == totalTable)
                    {
                        ValidationColumns.Append(" and gascomp.experiment_id=experiment.experiment_id;");
                    }
                    else
                    {
                        ValidationColumns.Append("  and gascomp.experiment_id=experiment.experiment_id");
                    }
                }


            }
            #endregion

            #region Chr Table
            if (Tables[i].ToString() == "chrcomp")
            {
                //If K=0 then there is only one table in the Table list.
                if (i == 0)
                {
                    Attributes.Append("chrcomp.H,chrcomp.C,chrcomp.N,chrcomp.S,chrcomp.Ash");
                    ValidationColumns.Append(" and chrcomp.experiment_id=experiment.experiment_id ");
                }
                else
                {
                    Attributes.Append(",chrcomp.H,chrcomp.C,chrcomp.N,chrcomp.S,chrcomp.Ash");

                    //if k=total table which means that table is the last/final table from the Table list.
                    if (i == totalTable)
                    {
                        ValidationColumns.Append(" and chrcomp.experiment_id=experiment.experiment_id;");
                    }
                    else
                    {
                        ValidationColumns.Append("  and chrcomp.experiment_id=experiment.experiment_id");
                    }
                }


            }
            #endregion

            #region Liquid Components Table
            if (Tables[i].ToString() == "liquidcomp")
            {
                //If K=0 then there is only one table in the Table list.
                if (i == 0)
                {
                    Attributes.Append("liquidcomp.aqueous,liquidcomp.oil,liquidcomp.water");
                    ValidationColumns.Append(" and liquidcomp.experiment_id=experiment.experiment_id ");
                }
                else
                {
                    Attributes.Append(",liquidcomp.aqueous,liquidcomp.oil,liquidcomp.water");

                    //if k=total table which means that table is the last/final table from the Table list.
                    if (i == totalTable)
                    {
                        ValidationColumns.Append(" and liquidcomp.experiment_id=experiment.experiment_id;");
                    }
                    else
                    {
                        ValidationColumns.Append("  and liquidcomp.experiment_id=experiment.experiment_id");
                    }
                }


            }
            #endregion

            #region Oil Components Table
            if (Tables[i].ToString() == "oilcomponents")
            {
                //If K=0 then there is only one table in the Table list.
                if (i == 0)
                {
                    Attributes.Append("oilcomponents.aliphatic,oilcomponents.aromatic,oilcomponents.polar");
                    ValidationColumns.Append(" and oilcomponents.experiment_id=experiment.experiment_id ");
                }
                else
                {
                    Attributes.Append(",oilcomponents.aliphatic,oilcomponents.aromatic,oilcomponents.polar");

                    //if k=total table which means that table is the last/final table from the Table list.
                    if (i == totalTable)
                    {
                        ValidationColumns.Append(" and oilcomponents.experiment_id=experiment.experiment_id;");
                    }
                    else
                    {
                        ValidationColumns.Append("  and oilcomponents.experiment_id=experiment.experiment_id");
                    }
                }


            }
            #endregion

            #region Oil physical properties Table
            if (Tables[i].ToString() == "oilphysprops")
            {
                //If K=0 then there is only one table in the Table list.
                if (i == 0)
                {
                    Attributes.Append("oilphysprops.density,oilphysprops.viscosity,oilphysprops.viscosity_temp,oilphysprops.flashPoint,oilphysprops.pourPoint,oilphysprops.pH,oilphysprops.HHV,oilphysprops.HeatOfCombustion,oilphysprops.WaterContent,oilphysprops.ConradsenCarbon");
                    ValidationColumns.Append(" and oilphysprops.experiment_id=experiment.experiment_id ");
                }
                else
                {
                    Attributes.Append(",oilphysprops.density,oilphysprops.viscosity,oilphysprops.viscosity_temp,oilphysprops.flashPoint,oilphysprops.pourPoint,oilphysprops.pH,oilphysprops.HHV,oilphysprops.HeatOfCombustion,oilphysprops.WaterContent,oilphysprops.ConradsenCarbon");

                    //if k=total table which means that table is the last/final table from the Table list.
                    if (i == totalTable)
                    {
                        ValidationColumns.Append(" and oilphysprops.experiment_id=experiment.experiment_id;");
                    }
                    else
                    {
                        ValidationColumns.Append("  and oilphysprops.experiment_id=experiment.experiment_id");
                    }
                }


            }
            #endregion


        }
        #endregion

        #region "Attributes For loop"
        for (int k = 0; QueryColumns.Count > k; k++)
        {


            #region Calorific analysis table attributes

            if (QueryColumns[k].ToString() == "calanal.moistureStatus")
            {
                if (k == 0)
                {
                    StringColumns.Append("calanal.moistureStatus='" + txtCalorificAnalysisMoistureStatus.Text + "'");
                }
                else
                {
                    StringColumns.Append("and calanal.moistureStatus='" + txtCalorificAnalysisMoistureStatus.Text + "'");
                }
            }

            if (QueryColumns[k].ToString() == "calanal.HHV")
            {
                if (k == 0)
                {
                    StringColumns.Append("calanal.HHV='" + txtCalorificAnalysisHHV.Text + "'");
                }
                else
                {
                    StringColumns.Append("and calanal.HHV='" + txtCalorificAnalysisHHV.Text + "'");
                }
            }

            if (QueryColumns[k].ToString() == "calanal.LHV")
            {
                if (k == 0)
                {
                    StringColumns.Append("calanal.LHV='" + txtCalorificAnalysisLHV.Text + "'");
                }
                else
                {
                    StringColumns.Append("and calanal.LHV='" + txtCalorificAnalysisLHV.Text + "'");
                }
            }


            #endregion

            #region Proximate Analysis Attributes
            if (QueryColumns[k].ToString() == "proxanal.moistureStatus")
            {
                if (k == 0)
                {
                    StringColumns.Append("proxanal.moistureStatus='" + txtProximateAnalysisMoistureStatus.Text + "'");
                }
                else
                {
                    StringColumns.Append("and proxanal.moistureStatus='" + txtProximateAnalysisMoistureStatus.Text + "'");
                }
            }

            if (QueryColumns[k].ToString() == "proxanal.moisture")
            {
                if (k == 0)
                {
                    StringColumns.Append("proxanal.moisture='" + txtProximateAnalysisMoisture.Text + "'");
                }
                else
                {
                    StringColumns.Append(" and proxanal.moisture='" + txtProximateAnalysisMoisture.Text + "'");
                }
            }

            if (QueryColumns[k].ToString() == "proxanal.ash")
            {
                if (k == 0)
                {
                    StringColumns.Append("proxanal.ash='" + txtProximateAnalysisAsh.Text + "'");
                }
                else
                {
                    StringColumns.Append(" and proxanal.ash='" + txtProximateAnalysisAsh.Text + "'");
                }
            }

            if (QueryColumns[k].ToString() == "proxanal.volatiles")
            {
                if (k == 0)
                {
                    StringColumns.Append("proxanal.volatiles='" + txtProximateAnalysisVolatiles.Text + "'");
                }
                else
                {
                    StringColumns.Append(" and proxanal.volatiles='" + txtProximateAnalysisVolatiles.Text + "'");
                }
            }

            if (QueryColumns[k].ToString() == "proxanal.fixedCarbon")
            {
                if (k == 0)
                {
                    StringColumns.Append("proxanal.fixedCarbon='" + txtProximateAnalysisFixedCarbon.Text + "'");
                }
                else
                {
                    StringColumns.Append(" and proxanal.fixedCarbon='" + txtProximateAnalysisFixedCarbon.Text + "'");
                }
            }

            #endregion

            #region Ash analysis attributes
                if (QueryColumns[k].ToString() == "ashanal.ashProdMethod")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ashanal.ashProdMethod='" + txtAshAnalysisProductionMethod.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and ashanal.ashProdMethod='" + txtAshAnalysisProductionMethod.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ashanal.CO2")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ashanal.CO2='" + txtAshanalysisCO2.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and ashanal.CO2='" + txtAshanalysisCO2.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ashanal.SO3")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ashanal.SO3='" + txtAshAnalysisSO3.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and ashanal.SO3='" + txtAshAnalysisSO3.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ashanal.P2O5")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ashanal.P2O5='" + txtAshAnalysisP2O5.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and ashanal.P2O5='" + txtAshAnalysisP2O5.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ashanal.SiO2")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ashanal.SiO2='" + txtAshAnalysisSiO2.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and ashanal.SiO2='" + txtAshAnalysisSiO2.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ashanal.Fe2O3")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ashanal.Fe2O3='" + txtAshAnalysisFe2O3.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and ashanal.Fe2O3='" + txtAshAnalysisFe2O3.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ashanal.Al2O3")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ashanal.Al2O3='" + txtAshAnalysisAl2O3.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and ashanal.Al2O3='" + txtAshAnalysisAl2O3.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ashanal.CaO")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ashanal.CaO='" + txtAshAnalysisCaO.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and ashanal.CaO='" + txtAshAnalysisCaO.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ashanal.MgO")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ashanal.MgO='" + txtAshAnalysisMgO.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and ashanal.MgO='" + txtAshAnalysisMgO.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ashanal.Na2O")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ashanal.Na2O='" + txtAshAnalysisNa2O.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and ashanal.Na2O='" + txtAshAnalysisNa2O.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ashanal.K2O")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ashanal.K2O='" + txtAshAnalysisK2O.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and ashanal.K2O='" + txtAshAnalysisK2O.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ashanal.TiO2")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ashanal.TiO2='" + txtAshAnalysisTiO2.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and ashanal.TiO2='" + txtAshAnalysisTiO2.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ashanal.Pb")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ashanal.Pb='" + txtAshAnalysisPb.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and ashanal.Pb='" + txtAshAnalysisPb.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ashanal.Cd")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ashanal.Cd='" + txtAshAnalysisCd.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and ashanal.Cd='" + txtAshAnalysisCd.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ashanal.Cl")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ashanal.Cl='" + txtAshAnalysisCl.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and ashanal.Cl='" + txtAshAnalysisCl.Text + "'");
                    }
                }


                if (QueryColumns[k].ToString() == "ashanal.Cu")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ashanal.Cu='" + txtAshAnalysisCu.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and ashanal.Cu='" + txtAshAnalysisCu.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ashanal.Hg")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ashanal.Hg='" + txtAshAnalysisHg.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and ashanal.Hg='" + txtAshAnalysisHg.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ashanal.Mn")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ashanal.Mn='" + txtAshAnalysisMn.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and ashanal.Mn='" + txtAshAnalysisMn.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ashanal.Cr")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ashanal.Cr='" + txtAshAnalysisCr.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and ashanal.Cr='" + txtAshAnalysisCr.Text + "'");
                    }
                }

            #endregion

            #region Material Attributes
                if (QueryColumns[k].ToString() == "material.name")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("material.name='" + txtMaterialName.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and material.name='" + txtMaterialName.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "material.source")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("material.source='" + txtMaterialSource.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and material.source='" + txtMaterialSource.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "material.handlingHistory")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("material.handlingHistory='" + txtMaterialHandlingHistory.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and material.handlingHistory='" + txtMaterialHandlingHistory.Text + "'");
                    }
                }
                #endregion

            #region Conversion Conditions Attributes
                if (QueryColumns[k].ToString() == "convconditions.gasBiomassRatio")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("convconditions.gasBiomassRatio='" + txtConversionCondGasBiomassRatio.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and convconditions.gasBiomassRatio='" + txtConversionCondGasBiomassRatio.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "convconditions.bedMedium")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("convconditions.bedMedium='" + txtConversionCondBedmedium.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and convconditions.bedMedium='" + txtConversionCondBedmedium.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "convconditions.conv_Regime")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("convconditions.conv_Regime='" + txtConversionCondConvRegime.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and convconditions.conv_Regime='" + txtConversionCondConvRegime.Text + "'");
                    }
                }


                if (QueryColumns[k].ToString() == "convconditions.feedRate_max")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("convconditions.feedRate_max='" + txtConversionCondFeedRateMax.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and convconditions.feedRate_max='" + txtConversionCondFeedRateMax.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "convconditions.feedRate_min")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("convconditions.feedRate_min='" + txtConversionCondFeedRateMin.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and convconditions.feedRate_min='" + txtConversionCondFeedRateMin.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "convconditions.feedSystem")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("convconditions.feedSystem='" + txtConversionCondFeedsystem.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and convconditions.feedSystem='" + txtConversionCondFeedsystem.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "convconditions.gasificationMed")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("convconditions.gasificationMed='" + txtConversionCondGasifimethod.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and convconditions.gasificationMed='" + txtConversionCondGasifimethod.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "convconditions.heatRate_max")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("convconditions.heatRate_max='" + txtConversionCondHeatrateMax.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and convconditions.heatRate_max='" + txtConversionCondHeatrateMax.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "convconditions.heatRate_min")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("convconditions.heatRate_min='" + txtConversionCondHeatrateMin.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and convconditions.heatRate_min='" + txtConversionCondHeatrateMin.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "convconditions.pressure")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("convconditions.pressure='" + txtConversionCondPressure.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and convconditions.pressure='" + txtConversionCondPressure.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "convconditions.reactorConfig")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("convconditions.reactorConfig='" + txtConversionCondReactorConf.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and convconditions.reactorConfig='" + txtConversionCondReactorConf.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "convconditions.resTime_max")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("convconditions.resTime_max='" + txtConversionCondResTimeMax.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and convconditions.resTime_max='" + txtConversionCondResTimeMax.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "convconditions.resTime_min")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("convconditions.resTime_min='" + txtConversionCondResTimeMin.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and convconditions.resTime_min='" + txtConversionCondResTimeMin.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "convconditions.sweptGasVelocity")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("convconditions.sweptGasVelocity='" + txtConversionCondSweepGasVol.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and convconditions.sweptGasVelocity='" + txtConversionCondSweepGasVol.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "convconditions.temp")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("convconditions.temp='" + txtConversionCondTemp.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and convconditions.temp='" + txtConversionCondTemp.Text + "'");
                    }
                }

                #endregion

            #region Ultimate Analysis Attributes

                if (QueryColumns[k].ToString() == "ultanal.moistureStatus")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ultanal.moistureStatus='" + txtUltimateAnalysisMoistureStatus.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and ultanal.moistureStatus='" + txtUltimateAnalysisMoistureStatus.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ultanal.moisture")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ultanal.moisture='" + txtUltimateAnalysisMoisture.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and ultanal.moisture='" + txtUltimateAnalysisMoisture.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ultanal.ash")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ultanal.ash='" + txtUltimateAnalysisAsh.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and ultanal.ash='" + txtUltimateAnalysisAsh.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ultanal.H")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ultanal.H='" + txtUltimateAnalysisH.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and ultanal.H='" + txtUltimateAnalysisH.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ultanal.C")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ultanal.C='" + txtUltimateAnalysisC.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and ultanal.C='" + txtUltimateAnalysisC.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "ultanal.N")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ultanal.N='" + txtUltimateAnalysisN.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and ultanal.N='" + txtUltimateAnalysisN.Text + "'");
                    }
                }


                if (QueryColumns[k].ToString() == "ultanal.O")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ultanal.O='" + txtUltimateAnalysisO.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and ultanal.O='" + txtUltimateAnalysisO.Text + "'");
                    }
                }


                if (QueryColumns[k].ToString() == "ultanal.Cl")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ultanal.Cl='" + txtUltimateAnalysisCl.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and ultanal.Cl='" + txtUltimateAnalysisCl.Text + "'");
                    }
                }


                if (QueryColumns[k].ToString() == "ultanal.S")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("ultanal.S='" + txtUltimateAnalysisS.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and ultanal.S='" + txtUltimateAnalysisS.Text + "'");
                    }
                }


                #endregion

            #region Structural Analysis Attributes

                if (QueryColumns[k].ToString() == "struct.lignin")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("struct.lignin='" + txtStructuralAnalysisLignin.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and struct.lignin='" + txtStructuralAnalysisLignin.Text + "'");
                    }
                }


                if (QueryColumns[k].ToString() == "struct.ligninMethod")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("struct.ligninMethod='" + txtStructuralAnalysisLigninMethod.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and struct.ligninMethod='" + txtStructuralAnalysisLigninMethod.Text + "'");
                    }
                }


                if (QueryColumns[k].ToString() == "struct.cellulose")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("struct.cellulose='" + txtStructuralAnalysisCellulose.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and struct.cellulose='" + txtStructuralAnalysisCellulose.Text + "'");
                    }
                }


                if (QueryColumns[k].ToString() == "struct.hemicellulose")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("struct.hemicellulose='" + txtStructuralAnalysisHemiCellulose.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and struct.hemicellulose='" + txtStructuralAnalysisHemiCellulose.Text + "'");
                    }
                }


                if (QueryColumns[k].ToString() == "struct.extractives")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("struct.extractives='" + txtStructuralAnalysisExtractives.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and struct.extractives='" + txtStructuralAnalysisExtractives.Text + "'");
                    }
                }


                if (QueryColumns[k].ToString() == "struct.cellwall")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("struct.cellwall='" + txtStructuralAnalysisCellWall.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and struct.cellwall='" + txtStructuralAnalysisCellWall.Text + "'");
                    }
                }


                if (QueryColumns[k].ToString() == "struct.pectin")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("struct.pectin='" + txtStructuralAnalysisPectin.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and struct.pectin='" + txtStructuralAnalysisPectin.Text + "'");
                    }
                }


                if (QueryColumns[k].ToString() == "struct.sol_sugars_stch")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("struct.sol_sugars_stch='" + txtStructuralAnalysisSol_Sugar_Sta.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and struct.sol_sugars_stch='" + txtStructuralAnalysisSol_Sugar_Sta.Text + "'");
                    }
                }


                if (QueryColumns[k].ToString() == "struct.xylan")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("struct.xylan='" + txtStructuralAnalysisXylan.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and struct.xylan='" + txtStructuralAnalysisXylan.Text + "'");
                    }
                }


                if (QueryColumns[k].ToString() == "struct.glucomannan")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("struct.glucomannan='" + txtStructuralAnalysisGlucomannan.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and struct.glucomannan='" + txtStructuralAnalysisGlucomannan.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "struct.galactan")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("struct.galactan='" + txtStructuralAnalysisGalactin.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and struct.galactan='" + txtStructuralAnalysisGalactin.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "struct.arabinan")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("struct.arabinan='" + txtStructuralAnalysisArabinan.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and struct.arabinan='" + txtStructuralAnalysisArabinan.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "struct.mannan")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("struct.mannan='" + txtStructuralAnalysisMannan.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and struct.mannan='" + txtStructuralAnalysisMannan.Text + "'");
                    }
                }
                #endregion

            #region Yield Attributes
                if (QueryColumns[k].ToString() == "yields.chr")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("yields.chr='" + txtYieldChr.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and yields.chr='" + txtYieldChr.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "yields.tar")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("yields.tar='" + txtYieldTar.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and yields.tar='" + txtYieldTar.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "yields.liquid")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("yields.liquid='" + txtYieldLiquid.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and yields.liquid='" + txtYieldLiquid.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "yields.gas")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("yields.gas='" + txtYieldGas.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and yields.gas='" + txtYieldGas.Text + "'");
                    }
                }
                #endregion

            #region Gas Attributes
                if (QueryColumns[k].ToString() == "gascomp.H2")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("gascomp.H2='" + txtGasH2.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and gascomp.H2='" + txtGasH2.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "gascomp.CO")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("gascomp.CO='" + txtGasCO.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and gascomp.CO='" + txtGasCO.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "gascomp.CO2")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("gascomp.CO2='" + txtGasCO2.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and gascomp.CO2='" + txtGasCO2.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "gascomp.CH4")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("gascomp.CH4='" + txtGasCH4.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and gascomp.CH4='" + txtGasCH4.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "gascomp.C2H4")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("gascomp.C2H4='" + txtGasC2H4.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and gascomp.C2H4='" + txtGasC2H4.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "gascomp.C2H2")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("gascomp.C2H2='" + txtGasC2H2.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and gascomp.C2H2='" + txtGasC2H2.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "gascomp.C2H6")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("gascomp.C2H6='" + txtGasC2H6.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and gascomp.C2H6='" + txtGasC2H6.Text + "'");
                    }
                }



                if (QueryColumns[k].ToString() == "gascomp.N2")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("gascomp.N2='" + txtGasN2.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and gascomp.N2='" + txtGasN2.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "gascomp.GCV")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("gascomp.GCV='" + txtGasGCV.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and gascomp.GCV='" + txtGasGCV.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "gascomp.Tar")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("gascomp.Tar='" + txtGasTar.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and gascomp.Tar='" + txtGasTar.Text + "'");
                    }
                }





                #endregion
            
            #region Chr Attributes
                if (QueryColumns[k].ToString() == "chrcomp.H")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("chrcomp.H='" + txtCharH.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and chrcomp.H='" + txtCharH.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "chrcomp.C")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("chrcomp.C='" + txtCharC.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and chrcomp.C='" + txtCharC.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "chrcomp.N")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("chrcomp.N='" + txtCharN.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and chrcomp.N='" + txtCharN.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "chrcomp.S")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("chrcomp.S='" + txtCharS.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and chrcomp.S='" + txtCharS.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "chrcomp.Ash")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("chrcomp.Ash='" + txtCharAsh.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and chrcomp.Ash='" + txtCharAsh.Text + "'");
                    }
                }

                


                #endregion

            #region Liquid Components Attributes
                if (QueryColumns[k].ToString() == "liquidcomp.aqueous")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("liquidcomp.aqueous='" + txtLiquidComponentsAqueous.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and liquidcomp.aqueous='" + txtLiquidComponentsAqueous.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "liquidcomp.oil")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("liquidcomp.oil='" + txtLiquidComponentsOil.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and liquidcomp.oil='" + txtLiquidComponentsOil.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "liquidcomp.water")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("liquidcomp.water='" + txtLiquidComponentsWater.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and liquidcomp.water='" + txtLiquidComponentsWater.Text + "'");
                    }
                }

               




                #endregion

            #region Oil Components Attributes
                if (QueryColumns[k].ToString() == "oilcomponents.aliphatic")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("oilcomponents.aliphatic='" + txtOilComponentsAliphatic.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and oilcomponents.aliphatic='" + txtOilComponentsAliphatic.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "oilcomponents.aromatic")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("oilcomponents.aromatic='" + txtOilComponentsAromatic.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and oilcomponents.aromatic='" + txtOilComponentsAromatic.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "oilcomponents.polar")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("oilcomponents.polar='" + txtOilComponentsPolar.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and oilcomponents.polar='" + txtOilComponentsPolar.Text + "'");
                    }
                }






                #endregion

           #region Oil physical properties Attributes
                if (QueryColumns[k].ToString() == "oilphysprops.density")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("oilphysprops.density='" + txtOilPhysicalPropertiesDensity.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append("and oilphysprops.density='" + txtOilPhysicalPropertiesDensity.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "oilphysprops.viscosity")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("oilphysprops.viscosity='" + txtOilPhysicalPropertiesViscosity.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and oilphysprops.viscosity='" + txtOilPhysicalPropertiesViscosity.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "oilphysprops.viscosity_temp")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("oilphysprops.viscosity_temp='" + txtOilPhysicalPropertiesViscostyTemp.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and oilphysprops.viscosity_temp='" + txtOilPhysicalPropertiesViscostyTemp.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "oilphysprops.flashPoint")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("oilphysprops.flashPoint='" + txtOilPhysicalPropertiesFlashPoint.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and oilphysprops.flashPoint='" + txtOilPhysicalPropertiesFlashPoint.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "oilphysprops.pourPoint")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("oilphysprops.pourPoint='" + txtOilPhysicalPropertiesPourPoint.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and oilphysprops.pourPoint='" + txtOilPhysicalPropertiesPourPoint.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "oilphysprops.pH")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("oilphysprops.pH='" + txtOilPhysicalPropertiesPh.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and oilphysprops.ph='" + txtOilPhysicalPropertiesPh.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "oilphysprops.HHV")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("oilphysprops.HHV='" + txtOilPhysicalPropertiesHHV.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and oilphysprops.HHV='" + txtOilPhysicalPropertiesHHV.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "oilphysprops.HeatOfCombustion")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("oilphysprops.HeatOfCombustion='" + txtOilPhysicalPropertiesHeatOfCompution.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and oilphysprops.HeatOfCombustion='" + txtOilPhysicalPropertiesHeatOfCompution.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "oilphysprops.WaterContent")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("oilphysprops.WaterContent='" + txtOilPhysicalPropertiesWaterContent.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and oilphysprops.WaterContent='" + txtOilPhysicalPropertiesWaterContent.Text + "'");
                    }
                }

                if (QueryColumns[k].ToString() == "oilphysprops.ConradsenCarbon")
                {
                    if (k == 0)
                    {
                        StringColumns.Append("oilphysprops.ConradsenCarbon='" + txtOilPhysicalPropertiesContradsenCarbon.Text + "'");
                    }
                    else
                    {
                        StringColumns.Append(" and oilphysprops.ConradsenCarbon='" + txtOilPhysicalPropertiesContradsenCarbon.Text + "'");
                    }
                }






                #endregion



            }

        #endregion

        #region "Get the final Table
        for (int p = 0; Tables.Count > p; p++)
            {
                if (p == 0)
                {
                    FinalTables.Append(Tables[p].ToString());
                }
                else
                {
                    FinalTables.Append("," + Tables[p].ToString());
                }
            }
        #endregion


        //This is the final query
            FinalQuery = "Select experiment.experimentName as ExperimentName," + Attributes + " " + "From experiment," + FinalTables + "  where" + " " + StringColumns + " " + ValidationColumns;

            ds = objServices.RunSQLQuery(FinalQuery);

            if (ds.Tables[0].Rows.Count == 0)
            {
                lblmsg.Text = "No records are found for the searched creteria";
                lblmsg.Visible = true;
            }
            trdgResult.Visible = true;
            dgFinalResult.DataSource = ds.Tables[0];
            Session["FilterExperiment"] = ds.Tables[0];
            dgFinalResult.DataBind();




        }


    }



